<?php
// 后台用户模块
class MainAction extends CommonAction {
	function _initialize() {
		$user_id = $this -> _session(C('USER_AUTH_KEY'));
		if (!$user_id) {
			//跳转到认证网关
			redirect(PHP_FILE . C('USER_AUTH_GATEWAY'));
		}
                
		$this -> assign_left_menu();
		$this -> _config = D("Config") -> get_config();
	}

	public function _before_index() {
		$model = M("Position");
		$list = $model -> where('status=1') -> order('sort asc') -> getField('id,name');
		$this -> assign('position_list', $list);

		$model = M("Rank");
		$list = $model -> where('status=1') -> order('sort asc') -> getField('id,name');
		$this -> assign('rank_list', $list);

		$model = M("Dept");
		$list = $model -> where('status=1') -> order('sort asc') -> getField('id,name');
		$this -> assign('dept_list', $list);

		$model = M("Rank");
		$list = $model -> where('status=1') -> order('sort asc') -> getField('id,name');
		$this -> assign('rank_list', $list);
	}
        
        public function mail() {
            $this->display('index');
        }
        
        public function order() {
            $this->display('index');
        }
        
         public function camera() {
            $this->display('index_camera');
        }
        
        public function process() {
            $this->display('index');
        }
        
        public function doc() {
            $this->display('index');
        }
        
        public function schedule() {
            $this->display('index');
        }
        
        public function notice() {
            $this->display('index');
        }
        public function user() {
            $this->display('index');
        }

protected function assign_left_menu() {
		$top_menu = cookie('top_menu');
		$model = M("Node");
		if(session('login_customer') !='1'){//2013.5.31如果不是会员客户
                    if ($this -> _session('administrator')) {
			$where = array('status' => 1, 'pid' => 0, );
                    } else {
                        $where = array('status' => 1, 'pid' => 0, 'id' => array('neq', 84));
                    }
                }else{
                        $where = array('status' => 1, 'pid' => 0, 'id' => array('in',"163"));
                }
                
		$list = $model -> where($where) -> order('sort asc') -> getField('id,name,url');
		$this -> assign('list_top_menu', $list);
                //var_dump($list);
		$user_id = $this -> get_user_id();
		if (!empty($top_menu)) {
			$this -> assign("top_menu_name", $model -> where("id=$top_menu") -> getField('name'));
		}
		if ($user_id) {
			if ($_SESSION['menu' . $user_id]) {
				//如果已经缓存，直接读取缓存
				$menu = $_SESSION['menu' . $user_id];
			} else {
				//读取数据库模块列表生成菜单项
				$menu = D("Node") -> access_list($user_id);

				//缓存菜单访问
				session('menu' . $user_id, $menu);
			}
			
			$common_list = D("Folder") -> get_common_list();
			$personal_list = D("Folder") -> get_person_list();
			$menu = array_merge($common_list, $personal_list, $menu);
                        //var_dump($menu);
			$tree = list_to_tree_new($menu, $top_menu);
                        $json_tree = json_encode(tree_menu4($tree));
                        //var_dump($json_tree);
			$this -> assign('html_left_menu', tree_menu3($tree));
                        $this -> assign('json_tree', $json_tree);
		}
	}
        
        protected function get_list_rows() {
		return $this -> _config['list_rows'];
	}

	protected function set_list_rows($num) {
		$this -> _list_rows = $num;
	}

}
?>